一、deVoid UIFramework使用教程
Step 1:
Right click on project view
Create -> deVoid UI -> UIFrame Prefab
then drag the Prefab onto your scene
Step 2:
Get a reference to your UI Frame and register some screens
1 | uiFrame.RegisterScreen("YourScreenId", yourScreenPrefab); |
Step 3:
Show your screens
1 | uiFrame.OpenWindow("YourWindowId"); |
Or, if you have some data payload
1 | uiFrame.OpenWindow("YourWindowId", yourWindowProperties); |
Step 4:
Now that you’re familiar with the API, right click on project view
** Create -> deVoid UI -> UI Settings**
Rig your UI Frame prefab as the UI Template, drag all your screens in the Screens To Register list and simply do
1 | uiFrame = yourUiSettings.CreateUIInstance(); |
Which will give you a new UI Frame instance and automatically do Step 2 for you.
Make sure to check out the examples repo and read the manual!
What?
The deVoid UI Framework (or devUI for short) is a simple architecture for UI handling and navigation in Unity. It enforces one simple rule: you can never directly access the internals of your UI code from external code, but anything else is fair game. You want to read data from Singletons from inside your UI? Sure. You want to sandwich mediators, views and controllers and do MVC by the book? Go for it. You want to skip the data passing functionalities and use your own MVVM framework? Power to you. Do whatever floats your boat and works best for your needs.
Why?
Having worked with mobile F2P games for years, I’ve done my fair share of UI. And I hate doing UI.
So I figured the more people learn how to do it, the smaller the chances that I ever have to do it again 🌈
(Also, sharing is caring and I’m secretly a hippie)
Features
Simple to extend and customize
Support for navigation history and queuing
Transition animations
Blocking user input while screens transition (especially handy for touch input)
Priority and layering
Focus on type safety and flexibility
Known Limitations
No built in support for controller navigation
二、deVoid UIFramework案例
![IMAGE](resources/FEFF2F9DF1BF974B97C5066050BB8752.jpg =1610x964)
这个项目试图演示deVoidUI框架的功能。
这些例子
- 使用Signals作为消息传递系统,
- DOTween作为补间库,
- 来自TheNounProject.com的图标。
框架试图尽可能不知道如何实现屏幕,但它试图实施一个非常具体的规则:您不能从外部访问内部UI代码。
除此之外,所有的事情都是公平的——你是知道必要的人和你的代码库应该有多复杂的人。
尽管它对于初学者来说足够简单,对于产品来说足够健壮,但在您的项目中使用它之前,我建议您阅读https://github.com/yankooliveira/uiframework的手册。
单击下面导航面板中的按钮查看一些示例。
当您试图显示面板或打开窗口时,您可以选择以Properties(属性)的形式传递数据有效负载。这是你的**ScreenController(屏幕控制器)**实现的强类型。
试着选择Assets文件夹中的PlayerData ScriptableObject并更改其值。
如果您不习惯将有效负载传递给UI,这可能看起来太麻烦了,但它可以帮助您分离关注点并减少耦合。而且,没有什么可以阻止您将非常动态的参数传入有效负载。
一个例子是这个Warning Pop-Up,它有多种格式,这取决于您传递给它的有效负载。
还要注意,弹出窗口本身没有任何代码来暗化屏幕;这些都是由UI框架本身控制的(因为这个预制件被设置为弹出式)。
点击下面的按钮几次,然后检查ConfirmationPopupController.cs中的代码。
UI框架并不真正关心你如何处理这个(事实上,你可以在Worldspace UI中有一个UI Screenspace Camera。
这样做的好处是,你可以直接在UI预制件中添加其他Unity元素,如3d对象、线条渲染器和粒子系统。
你会受限于UI是使用一个Ortographic相机,你需要调整着色器如果你需要透明,但是它可以节省你的成本使用RenderTextures和允许你有诸如后处理效果直接在UI相机。
使用Screenspace-Camera的一个警告是,你所有的通常用于投影到Screenspace Overlay UI的操作都需要一个额外的跳跃:你需要从
- 本文作者: 梁俊可
- 本文链接: http://ljk3d.com/2022/04/19/unityNote/UnityUIFramework/deVoid UIFramework使用说明/
- 版权声明: 梁俊可工作室